import * as actionTypes from './actionTypes';
import axios from 'axios';
import { fromJS } from 'immutable';

const changeList = (list) => ({
    type: actionTypes.CHANGE_LIST,
    list: fromJS(list),
    totalPage: Math.ceil(list.length / 10),
})
export const searchFocus = () => ({type: actionTypes.SEARCH_FOCUS});
export const searchBlur = () => ({type: actionTypes.SEARCH_BLUR});
export const mouseEnter = () => ({type: actionTypes.MOUSE_ENTER});
export const mouseLevel = () => ({type: actionTypes.MOUSE_LEVEL});
export const changePage = (page) => ({type: actionTypes.CHANGE_PAGE, page});
export const getList = () => {
    return async (dispatch) => {
        try {
            const val = await axios.get("/mock/api/headerList.json");
            const data = val.data;
            if (data.success) {
                dispatch(changeList(data.data));
            } else {
                console.error(data.msg);
            }
        } catch(e) {
            console.error("网络发送失败:" + e);
        }
    }
}